#include <iostream>
#include <set>
#include <iterator>
#include <sstream>
#include <iterator>
#include <algorithm>

using namespace std;
#define _SKIP_LINE_ do{scanf("%*[^\n]"); getc(stdin);}while(0)
ostringstream oss;
typedef multiset<short>::iterator Iter;

short Word() { 
	short d; 
	cin >> d; 
	return d; 
}

//(AB), (A), (YZ), (B)
short Strategy(multiset<short>& group) {
	short total = 0, A, B, Y, Z;
	A = *(group.begin());
	group.erase(group.begin());
	B = *(group.begin());
	group.erase(group.begin());
	while(group.size() > 1) {
		Iter P =  group.end();
		Z = *(--P);
		Y = *(--P);
		
		if( B == Z || B == Y) break;
		
		group.erase(--(group.end()));
		group.erase(--(group.end()));

		total += B;
		oss << A << " " << B << endl;
		
		total += A;
		oss << A << endl;
		
		total +=  Z;
		oss << Y << " " << Z << endl;	

		total += B;
		oss << B << endl;
	}
	if(group.size() == 1) {
		Z =  *(group.begin());
		total += Z + A + B;
		oss << A << " " << Z << endl;
		oss << A << endl;
		oss << A << " " << B << endl;
	} else if(group.empty() == true) {
		total += B;
		oss << A << " " << B << endl;
	} else {
		while(group.empty() == false) {
			Z = *(--group.end());
			group.erase(--(group.end()));
			total += A + Z;
			oss << A << " " << Z << endl;
			oss << A << endl;
		}
		total += B;
		oss << A << " " << B << endl;
	}
	return total;
}

short Compute(const multiset<short>& group) {
	multiset<short>::const_iterator P = group.begin();
	short A = *P;
	short total = 0;
	while(++P != group.end()) {
		total += A + *P;	
	}
	return total-A;
}

void cross_brdge(multiset<short>& group) {
	oss.clear();
	oss.str("");
	multiset<short> backup(group);
	short _total = Compute(group); 
	short total = Strategy(group);
	if(total < _total) {
		cout << total << endl;
		cout << oss.str();
	} else {
		cout << _total << endl;
		short A = *(backup.begin());
		short Z = *(--backup.end());
		backup.erase(backup.begin());
		backup.erase(--(backup.end()));
		cout << A << " " << Z << endl;
		while(backup.empty() == false) {
			Z = *(--backup.end());
			backup.erase(--(backup.end()));
			cout << A << endl;
			cout << A << " " << Z << endl;
		}
	}
}

/* main
 *  * */
int main() {
	std::ios_base::sync_with_stdio (true);
	short testcases = 0;
	short people = 0;
	cin >> testcases;
	multiset<short> group;
	while(testcases-- > 0 && cin.eof() != true) {
		cin >> people;
		group.clear();
		generate_n(inserter(group, group.end()), people, Word);
		cross_brdge(group);
		if(testcases > 0) cout << endl;
	}
	return 0;
}
